if (typeof Site == "undefined") {
    Site = {}
}
Site.manageMode = false;//浏览模式，非登录状态

/**
 *功能：网站在非可视化状态下需要加载的文件
 *主要是初始化页面的方法。注意：可视化状态下 不加载此文件
 */
$(document).ready(function () {
    $("#webFooterbkcolumn").show();
    Site.initFloatModule();
    Site.initNavigation();
    Site.styleDesignInit();
    Site.layoutInfloatModuleInit();
    Site.imgShapeShowInit();
    Site.logoInitScroll();
});

Site.initNavigation = function () {
    var url = '/load_navigation_style.jspx';
    $.ajax({
        url: url,
        crossDomain: true,
        xhrFields:{withCredentials:true},
        success: function(data) {
            if (data.showNav == 1) {
                _replaceStyleCss(data.navStyleData);
            }
        }
    });


    function _replaceStyleCss(d) {
        var t = $('.navForm').attr('_tplSol');
        var s = $('#stylemodule').html();
        if (s.length <= 0) {
            $('#stylemodule').append(d);
            return;
        }
        $('#stylemodule').remove();
        var k = s.split("\n");
//		var kk = new Array();
//		for(var i = 0;i<k.length;i++){
//			//先删除旧的设置
//			if(k[i].indexOf('#modulenav') == -1 && k[i].indexOf('#mainnav') == -1
//					&& k[i].indexOf('.subnav') == -1 && k[i].indexOf('.mainnav') == -1){
//				kk.push(k[i]);
//			}
//		}
//		if(!JRF.isNull(d)){
//			var h = d.split("\n");
//			for(var i=0;i<h.length;i++){
//				kk.push(h[i]);
//			}
//		}
        $("head").append('<style type="text/css" id="stylemodule">' + k.join("\n") + "</style>");
        $("head").append("<script language='javascript' src='/jrfr/js/Site.min.js'></script>");
        $("head").append("<script language='javascript' src='/res/common/js/jrf.min.js'></script>");
//		var ww = Site.getModuleStyleCss('nav'+t+' .navigationBox'+m);
//		var wn = Site.getModuleStyleCss('nav'+t+' .navForm');
//		if(ww.indexOf('px')<0){
//			$('#modulenav'+t).width('100%');
//			JRF.dom.find('#navigationBox'+m).width('100%');
//			JRF.dom.find('.navCenterContent').width('100%');
//		}else{
//			JRF.dom.find('#navigationBox'+m).width(1000+'px');
//			JRF.dom.find('.navForm').width(wn.substring(wn.indexOf(":")+1,wn.indexOf(";")));
//			navWidth();
//			//$('#modulenav'+t).width(width+52);
//		}

    }
}

/*功能：初始化侧停模块*/
Site.initFloatModule = function () {
    $('#main .form').filter(function () {
        return $(this).attr('_side') || $(this).attr('_lock');
    }).each(function () {
        var b = $(this);
        var c = b.attr('_side');
        var l = b.attr('_lock');
        var d = b.attr('id');
        var bw = b.outerWidth();
        var bh = b.height();
        var winW = $(window).width();
        if (c == 1) {
            var f = [];
            var p = b.parent();
            var m = d.substring(6, d.length);
            var e = 0;
            var i = JRF.isNull(b.find('.titeText').text()) ? "" : b.find('.titeText').text();
            if ($('#sideBtn' + m).length > 0) {
                $('#sideBtn' + m).remove();
            }
            var arr = b.attr('class').split(' ');
            if (p.hasClass('floatLeftForm')) {
                f = ['<div id="sideBtn' + m + '" class="sideBtn ' + arr[arr.length - 1] + '"><div class="g_sideBtn_t g_sb_rt"></div><div class="g_sideBtn_c g_sb_rc"><span class="g_sideBtn_tl">' + i + '</span></div><div class="g_sideBtn_b g_sb_rb"></div><div class="g_sideBtn_extend g_sb_re"></div></div>'];
                b.animate({left: -bw}, {queue: false, duration: 0});
                b.bind('mouseenter', MUTIL.bindSideInLft).bind('mouseleave', MUTIL.bindSideOutLft);
                e = 0;
            } else if (p.hasClass('floatRightForm')) {
                f = ['<div id="sideBtn' + m + '" class="sideBtn ' + arr[arr.length - 1] + ' "><div class="g_sideBtn_t g_sb_lt"></div><div class="g_sideBtn_c g_sb_lc"><span class="g_sideBtn_tl">' + i + '</span></div><div class="g_sideBtn_b g_sb_lb"></div><div class="g_sideBtn_extend g_sb_le"></div></div>'];
                b.animate({left: winW}, {queue: false, duration: 0});
                b.bind('mouseenter', MUTIL.bindSideInRgt).bind('mouseleave', MUTIL.bindSideOutRgt);
                e = 1;
            }
            b.append(f.join(''));
            MUTIL.setSideBtnPostion(m, b, e);
        }
        if (l == 1) {
            b.css('position', 'fixed');
        }
    });
}

Site.styleDesignInit = function () {
    //布局包裹
    $('#main div[class^="row-fluid"]').addClass('clearfix').wrap('<div class="lyrow"><div class="view"></div></div>');
    $('#page_head_module div[class="row-fluid-1"]').addClass('clearfix').wrap('<div class="lyrow pageHeadlyrow"><div class="view"></div></div>');
    $('#webFooterbkcolumn div[class="row-fluid-1"]').addClass('clearfix').wrap('<div class="lyrow webFooterbklyrow"><div class="view"></div></div>');
};

/**
 * 布局内浮动模块加载
 * 20171103 mxs
 */
Site.layoutInfloatModuleInit = function () {

    $(".form[_float=1]").each(function () {
        $(this).css("position", "absolute");
    });




};

Site.imgShapeShowInit = function(){
    $(".pic_module").each(function(){

        var moduleId = $(this).find("input[name=moduleId]").val();
        if(moduleId == 351){
            var shapetype = $(this).find("input[name=attr_shapetype]").val();

                var c= $(this).find("> div");
                var imgWidth = $(this).find("input[name=attr_imageWidth]").val();
                var imgHeight = $(this).find("input[name=attr_imageHeight]").val();
                var radiustext = $(this).find("input[name=attr_radius]").val();

                Site.imgShapeShow(c,shapetype,imgWidth,imgHeight,radiustext);

        }

    });
}


Site.logoInitScroll =function (){
    $(window).scroll(function(){

        var position =  $("#logo_picture").css("position");
        if(position != "fixed"){
            theAbsoluteTop =  $("#logo_picture").position().top;
            var theFixedTop =  $("#logo_picture").offset().top;
            var theAbsoluteLeft =  $("#logo_picture").position().left;
            var theFixedLeft =  $("#logo_picture").offset().left;
            $("#logo_picture").attr("absolutetop",theAbsoluteTop);
            $("#logo_picture").attr("fixedtop",theFixedTop);
            $("#logo_picture").attr("absoluteleft",theAbsoluteLeft);
            $("#logo_picture").attr("fixedleft",theFixedLeft);

        }
        var newAbsoluteTop =  $("#logo_picture").attr("absolutetop");
        var newFixedTop =  $("#logo_picture").attr("fixedtop");
        var newAbsoluteLeft =  $("#logo_picture").attr("absoluteleft");
        var newFixedLeft =  $("#logo_picture").attr("fixedleft");


        if($(".header_top").length>0){
            newFixedTop = newFixedTop-$(".header_top").height();
        }

        if ($("#logo_picture").attr("fixation") == 1){
            if($(window).scrollTop() > newFixedTop){
                var top = 0;
                if($(".header_top").length>0){
                    top = $(".header_top").height();
                }
                $("#logo_picture").css({
                    "position": "fixed",
                    "top": top,
                    "left": newFixedLeft+"px"
                })
                $("#logo_picture").draggable("disable");
            }else{
                $("#logo_picture").css({
                    "position": "absolute",
                    "top": newAbsoluteTop+"px",
                    "left": newAbsoluteLeft+"px"
                })
                $("#logo_picture").draggable("enable");
            }
        }else{
            $("#logo_picture").css({
                "position": "absolute",
                "top": newAbsoluteTop+"px",
                "left": newAbsoluteLeft+"px"
            })
            $("#logo_picture").draggable("enable");
        }
    })
}